<?php
	require_once '../mysql_connection/for_m_users.php';
	
	session_name('YourVisitID');
	session_start ();
	$error = array ();
	
	if (isset ( $_SESSION ['name'] )) {
		if(isset($_POST['delete_user'])){
			$uname = $_POST['delete_user'];
			$delete_ok = deleteUser($uname);
		}
		$users = getAllUser();//获得所有用户
	} else {
		$error [] = 'You have not login!';
	}
	
	if(isset($_POST['show_comment'])){
		$uname = $_POST['show_comment'];
		$user_comment = getUserComment($uname);
	}
?>

<?php 
include ('../include_htmls/manage_head.html');
?>

<?php
	if (empty ( $error )) {
?>
	<table cellspacing="0" cellpadding="3" border="1" align="center" width="800" height="100">
    			    					<tr>
    			    					    <th align="center">Name</th>
    			    					    <th align="center">Password</th>
    			    					    <th align="center">Stage</th>
    			    					    <th align="center">Gender</th>
    			    					    <th align="center">Score</th>
    			    					    <th align="center">GetComment</th>
    			    					    <th align="center">DeleteUser</th>
    			    					</tr>
<?php
		foreach ($users as $oneuser){
?>
    			    					<tr>
    			    						<th align="center"><?php echo $oneuser[0];?></th>
    			    						<th align="center"><?php echo $oneuser[1];?></th>
    			    						<th align="center"><?php echo $oneuser[2];?></th>
    			    						<th align="center"><?php echo $oneuser[3];?></th>
    			    						<th align="center"><?php echo $oneuser[4];?></th>
    			    						<th align="center">
    			    							<form action="manage_user.php" method="post">
    			    								<input type="submit" value="show comment">
    			    								<input type="hidden" value=<?php echo "\"".$oneuser[0]."\""?>" name="show_comment">
    			    							</form>
    			    						</th>
    			    						<th align="center">
    			    							<form action="manage_user.php" method="post">
    			    								<input type="submit" value="delete user">
    			    								<input type="hidden" value=<?php echo "\"".$oneuser[0]."\""?>" name="delete_user">
    			    							</form>
    			    						</th>
    			    					</tr>
<?php 	}
?>
</table>
     <HR style="border:3 double #987cb9" width="100%" color=#987cb9 SIZE=3>
<?php 
		if($delete_ok){
			echo "Delete Ok.";
		}
		if(!empty($user_comment)){
?>
     <table cellspacing="0" cellpadding="3" border="1" align="center" width="800" height="100">
    			    					<tr>
    			    					    <th align="center">Name</th>
    			    					    <th align="center">Goods</th>
    			    					    <th align="center">Content</th>
    			    					    <th align="center">Time</th>
    			    					    <th align="center">Delete</th>
    			    					</tr>
<?php 
			foreach ($user_comment as $onecomment){
?>
    			    					<tr>
    			    						<th align="center"><?php echo $onecomment[1];?></th>
    			    						<th align="center"><?php echo $onecomment[4];?></th>
    			    						<th align="center"><?php echo $onecomment[2];?></th>
    			    						<th align="center"><?php echo $onecomment[5];?></th>
    			    						<th align="center">
    			    							<form action="manage_user.php" method="post">
    			    								<input type="submit" value="DELETE">
    			    								<input type="hidden" value=<?php echo "\"".$onecomment[0]."\""?> name="delete_comment">
    			    							</form>
    			    						</th>
    			    					</tr>
<?php 	
			}
?>
	</table>
<?php
		}
	} else {
	echo '<h1 align="center" id="mainhead">Error!</h1>
	<p align="center" class="error">The following error(s) occurred:<br />';
	foreach ( $error as $msg ) {
		echo " - $msg<br />\n";
	}
	echo '</p><p align="center" >Please login first.</p>';
	echo '<p align="center" ><a href="login.php"><img src="../images/manager_login.jpg" width="100" hight="25" border="0"/></a></p>';
}
?>

<?php
include ('../include_htmls/manage_foot.html');
?>
